package com.huwaiwai.sort;

/**
 * 插入排序实现
 * Created by hww on 2018/12/6 11:03 PM.
 */
public class InsertionSort {



    public static void insertionSort(int [] disorderedList) {
        int length = disorderedList.length;
        for (int i = 1; i < length; i++) {
            int current = disorderedList[i];
            for (int j = 0; j < i; j++) {
                if (isInsertable(current, disorderedList[j])) {
                    System.arraycopy(disorderedList, j, disorderedList, j + 1, i - j);
                    disorderedList[j] = current;
                    break;
                }
            }
        }
    }

    private static boolean isInsertable(int current, int original) {
        return current < original;
    }


}
